/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.jgls.bi.dataprocess;

import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;

/**
 *
 * @author Administrator
 */
public class U8JdbcDao extends JdbcDaoSupport {

    private String strCcode;
    private int iperiod;
    private int iBal;
    private String sql = "";
    private int ip1 = 0,  ip2 = 0;
    private int ibalance = 0,  ibalance2 = 0;
    private ArrayList<Integer> lstT;
    private List<Integer> lstT2;
    int i = 0;

    public String getStrCcode() {
        return strCcode;
    }

    public void setStrCcode(String strCcode) {
        this.strCcode = strCcode;
    }

    public int getIperiod() {
        return iperiod;
    }

    public void setIperiod(int iperiod) {
        this.iperiod = iperiod;
    }

    public int getBalance() {
        System.out.println("now processing U8's Data->SupId:" + strCcode+" iperiod:"+iperiod);
        ibalance  = 0;
        ibalance2 = 0;
        iBal=0;
        ip1 = iperiod;
        ip2 = iperiod - 1;
        JdbcTemplate jt = getJdbcTemplate();
        sql = "select count(me)  from gl_accsum where ccode=? and iperiod=?";
        Object[] params = new Object[]{strCcode, ip1};
        int[] types = {Types.VARCHAR, Types.INTEGER};
        ibalance = jt.queryForInt(sql, params, types);
        if (ibalance > 0) {
            //获取上月余额
            sql = "select isnull(CEILING(me),0)  from gl_accsum where ccode=? and iperiod=?";
            ibalance = jt.queryForInt(sql, params, types);
            //获取本月发生
            sql = "select isnull(CEILING(sum(mc) - sum(md) ),0)  from gl_accvouch " +
                    "where ccode=? and iperiod=? and iflag is null";
            params = new Object[]{strCcode, ip1};
            ibalance2 = jt.queryForInt(sql, params, types);
        }
        //计算合计
        iBal = ibalance + ibalance2;
        return iBal;
    }
}
